function compute_intersection_sync(arr1, arr2, callback) {
    var results = [];
    for (var i = 0; i < arr1.length; i++) {
        for (var j = 0; j < arr2.length; j++) {
            if(arr2[j] === arr1[i]) {
                results[results.length] = arr2[j];
                break;
            }
        }
    }
    callback(null, results);
}

function compute_intersection(arr1, arr2, callback) {
    var bigger = arr1.length > arr2.length ? arr1 : arr2;
    var smaller = bigger === arr1 ? arr2 : arr1;
    var biglen = bigger.length;
    var smlen = smaller.length;
    var sidx = 0;
    var size = 10;
    var result = [];
    function sub_compute_intersection() {
        console.log(sidx);
        if (sidx > 0) { console.timeEnd('tick'); }
        for (var i = sidx; i < (sidx + size) && i < biglen; i++) {
            for (var j = 0; j < smlen; j++) {
                if (bigger[i] === smaller[j]) {
                    result.push(smaller[j]);
                    break;
                }
            }
        }
        if (i >= biglen) {
            callback(null, result);
        } else {
            sidx += size;
            console.time('tick');
            process.nextTick(sub_compute_intersection);
        }
    }
    sub_compute_intersection();
}

var a1 = [3476, 2457, 7547, 34523, 3, 6, 7, 2, 77, 8, 2345, 7623457, 2347, 23572457, 
            237457, 234869, 237, 24572457524];
var a2 = [3476, 75347547, 2457634563, 56763472, 34574, 2347, 7, 34652364, 13461346, 
            572346, 23723457234, 237, 234, 24352345, 537, 2345235, 2345675, 34534,
        7582768, 284835, 8553577, 2577257, 545634, 457247247, 2345];
console.time('async')
compute_intersection(a1, a2, function (err, results) {
    if (err) {
        console.log(err);
    } else {
        console.log(results);
        console.log('async end');
        console.timeEnd('async');
    }
})
console.time('sync')
compute_intersection_sync(a1, a2, function (err, results) {
    if (err) {
        console.log(err);
    } else {
        console.log(results);
        console.log('sync end');
        console.timeEnd('sync');
    }
})